import { EggAppConfig, PowerPartial } from "egg";
import { dialect } from "../db";
import * as path from "path";
import pkjson = require("../package.json");

const {
  mysql: { production: dbConfig }
} = dialect;

export default () => {
  const config: PowerPartial<EggAppConfig> = {};

  config.logger = {
    dir: path.resolve(__dirname, "..", "logs", pkjson.name + "-prod")
  };

  config.mysql = {
    client: {
      host: dbConfig.host,
      port: dbConfig.port,
      user: dbConfig.username,
      password: dbConfig.password,
      database: dbConfig.database
    },
    app: true,
    agent: false
  };
  config.sequelize = {
    dialect: dbConfig.dialect,
    host: dbConfig.host,
    port: dbConfig.port,
    username: dbConfig.username,
    password: dbConfig.password,
    database: dbConfig.database,
    define: {
      timestamps: true,
      freezeTableName: true
    }
  };
  return config;
};
